<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>修改代理商</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../bangnuo/admin/layui/css/layui.css" media="all">
</head>

<body>
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin">
    <div class="layui-form-item">
        <label class="layui-form-label">编号</label>
        <div class="layui-input-inline">
            <input type="text" name="agentNumber" id="agentNumber" lay-verify="required" placeholder="请输入编号"
                   autocomplete="off" class="layui-input" readonly="readonly">
            <input type="hidden" name="agentUuid" id="agentUuid" lay-verify="required" placeholder="请输入代理商id"
                   autocomplete="off" class="layui-input" readonly="readonly">
            <a style="color: red;">代理商编号不可修改</a>
            <br/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">代理商名称</label>
        <div class="layui-input-inline">
            <input type="text" name="agentCompanyName" id="agentCompanyName" lay-verify="required"
                   placeholder="请输入代理商名称" autocomplete="off" class="layui-input">
            <br/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名</label>
        <div class="layui-input-inline">
            <input type="text" name="agentUsername" id="agentUsername" lay-verify="required" placeholder="请输入登录名"
                   autocomplete="off" class="layui-input" readonly="readonly">
            <a style="color: red;">代理商登录名不可修改</a>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录密码</label>
        <div class="layui-input-inline">
            <input type="text" name="agentPassword" id="agentPassword" placeholder="请输入登录密码" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="agentName" id="agentName" lay-verify="required" placeholder="请输入负责人姓名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人身份证</label>
        <div class="layui-input-inline">
            <input type="text" name="agentCard" id="agentCard" lay-verify="required" placeholder="请输入负责人身份证"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">开户行</label>
        <div class="layui-input-block" style="width: 200px;">
            <select id="agentIt" name="agentIt" lay-verify="required">
                <option value="0"></option>
                <option value="4">农业银行</option>
                <option value="5">工商银行</option>
                <option value="7">民生银行</option>
                <option value="8">农商银行</option>
                <option value="9">建设银行</option>
                <option value="10">招商银行</option>
                <option value="11">交通银行</option>
                <option value="12">海峡银行</option>
                <option value="13">兴业银行</option>
                <option value="14">中国银行</option>
                <option value="15">中信银行</option>
                <option value="16">中国邮政</option>
                <option value="17">东莞银行</option>
                <option value="18">中国光大银行</option>
                <option value="20">光大银行</option>
                <option value="21">广发银行</option>
                <option value="22">武陟射阳村镇银行</option>
                <option value="23">农村信用社</option>
                <option value="24">江苏长江商业银行</option>
                <option value="25">成都银行</option>
                <option value="26">浙江民泰商业银行</option>
                <option value="27">包商银行</option>
                <option value="28">平安银行</option>
                <option value="29">内蒙古包头市商业银行</option>
                <option value="30">甘肃银行</option>
                <option value="31">潍坊银行</option>
                <option value="32">济宁银行</option>
                <option value="33">浦发银行</option>
                <option value="34">陕西信合</option>
                <option value="35">兰州银行</option>
                <option value="36">辽阳银行</option>
                <option value="37">榆林农村商业银行</option>
                <option value="38">长安银行</option>
                <option value="39">江西赣州银座村镇银行</option>
                <option value="40">青岛银行</option>
                <option value="41">广州银行</option>
                <option value="42">廊坊银行</option>
                <option value="43">锦州银行</option>
                <option value="44">桂林银行</option>
                <option value="45">长沙银行</option>
                <option value="46">云南昆明富滇银行</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支行名称</label>
        <div class="layui-input-inline">
            <input type="text" name="agentBranch" id="agentBranch" lay-verify="required" placeholder="请输入支行名称"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">持卡人姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="agentBankCardName" id="agentBankCardName" lay-verify="required"
                   placeholder="请输入持卡人姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">银行卡号</label>
        <div class="layui-input-inline">
            <input type="text" name="agentBankCard" id="agentBankCard" lay-verify="required" placeholder="请输入银行卡号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input type="text" name="agentPhone" id="agentPhone" lay-verify="required" placeholder="请输入邮箱账号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电子邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="agentEmail" id="agentEmail" lay-verify="required" placeholder="请输入邮箱账号"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">招代理</label>
        <div class="layui-input-block">
            <input type="radio" id="radioDaili1" name="agentAgent" value="1" title="是" checked>
            <input type="radio" id="radioDaili2" name="agentAgent" value="0" title="否">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">全国</label>
        <div class="layui-input-block">
            <input type="radio" id="agentNational1" name="agentNational" value="1" title="是" checked>
            <input type="radio" id="agentNational2" name="agentNational" value="0" title="否">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input id="status1" type="radio" name="agentState" value="1" title="正常">
            <input id="status2" type="radio" name="agentState" value="0" title="锁定">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合作时间</label>
        <div class="layui-input-inline">
            <input type="text" name="agentCreateTime" id="agentCreateTime" lay-verify="required" placeholder="请选择"
                   autocomplete="off" class="layui-input" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">到期时间</label>
        <div class="layui-input-inline">
            <input type="text" name="agentEndTime" id="agentEndTime" lay-verify="required" placeholder="请选择"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级代理</label>
        <div class="layui-input-block" style="width: 200px;">
            <select name="agentIdAgentId" id="agentIdAgentId">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" name="agentNote" id="agentNote" placeholder="请输入备注" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-btn-container" style="padding-bottom: 10px; margin-left: 110px; margin-right: -110px;">
        <button class="layui-btn" lay-submit lay-filter="agent-form" data-type="close">立即提交</button>
    </div>
</div>
</body>

<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<script>
    layui.use('layer',function () {
        var layer = layui.layer;

        $("#agentCard").blur(function () {
            var card = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;//身份证
            if(!card.test($("#agentCard").val())){
                layer.msg("请输入正确的身份证号");
            }
        });
        $("#agentPhone").blur(function () {
            var phone = /^[1][3,4,5,7,8][0-9]{9}$/; //"请输入正确的手机号"
            if(!phone.test($("#agentPhone").val())){
                layer.msg("请输入正确的电话号");
            }
        });
        $("#agentEmail").blur(function () {
            var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //"邮箱格式不正确"
            if(!email.test($("#agentEmail").val())){
                layer.msg("请输入正确的邮箱号");
            }
        });
        $("#agentBankCard").blur(function () {
            var regExp  = /^[1-9]\d{7,29}$/;  //"银行卡格式不正确"
            if(!regExp .test($("#agentBankCard").val())){
                layer.msg("请输入正确的银行卡号");
            }
        });

    });
</script>
<script>
    layui.use(['laydate', 'form', 'upload', 'layer'], function () {

        var form = layui.form,
            laydate = layui.laydate;
        laydate.render({
            elem: '#agentEndTime' //指定元素
            ,
            format: 'yyyy-MM-dd HH:mm:ss'
        });


        var resultData;
        var htmls = '<option value="">请选择</option>'; //全局变量

        //检查项目添加到下拉框中
        /*$.ajax({
            url: '/agentEntity/agent',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                resultData = data.queryResult.list;
                for (var x in resultData) {
                    htmls += '<option value = "' + resultData[x].id + '">' + resultData[x].name + '</option>';
                }
                $("#agentIdAgentId").html(htmls);
                form.render('select');
                //重新渲染 固定写法
            }
        })*/
    });
</script>
<!--加载表单组件样式-->
<script>
    layui.config({
        base: '../../../bangnuo/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function () {
        var $ = layui.$,
            form = layui.form,
            upload = layui.upload;

        upload.render({
            elem: '#layuiadmin-upload-useradmin',
            url: layui.setter.base + 'json/upload/demo.js',
            accept: 'images',
            method: 'get',
            acceptMime: 'image/*',
            done: function (res) {
                $(this.item).prev("div").children("input").val(res.data.src)
            }
        });
    })
</script>
<script type="text/javascript">
    layui.use(['laydate', 'form', 'upload', 'layer'], function () {
        var form = layui.form;
        $(document).ready(function () {
            //获取地址栏路径
            var url = window.location.href;
            //获取“=”的下标
            var pos = url.indexOf("=");
            //获取“=”后的全部字符（用户id）
            var id = url.substring(pos + 1, url.length);
            $.ajax({
                url: "/agentEntity/findById/" + id,
                contentType: "application/json;charset=UTF-8",
                type: "GET",
                success: function (res) {
                    console.log("根据id获取res", res);
                    $("#agentUuid").val(res.object.id);
                    $("#agentNumber").val(res.object.number);
                    $("#agentCompanyName").val(res.object.companyName);
                    $("#agentUsername").val(res.object.username);
                    $("#agentIdAgentId").val(res.object.agentIdAgentId);
                    //$("#agentPassword").val(data.data.agentPassword);
                    $("#agentName").val(res.object.name);
                    $("#agentCard").val(res.object.card);
                    $("#agentBranch").val(res.object.branch);
                    $("#agentBankCardName").val(res.object.bankCardName);
                    $("#agentBankCard").val(res.object.bankCardNumber)
                    $("#agentPhone").val(res.object.phone);
                    $("#agentEmail").val(res.object.email);
                    $("#agentCreateTime").val(dateFormat(res.object.createTime));
                    $("#agentEndTime").val(dateFormat(res.object.overdueTime));
                    $("#agentNote").val(res.object.remark);
                    if (res.object.status == 1) {
                        //获取节点
                        $("#status1").attr("checked", "checked");
                        $("#status2").removeAttr("checked");
                        form.render();
                    } else {
                        $("#status1").removeAttr("checked");
                        $("#status2").attr("checked", "checked");
                        form.render();
                    }

                    if (res.object.agentType == 1) {
                        $("#radioDaili1").attr("checked", "checked");
                        $("#radioDaili2").removeAttr("checked");
                        form.render();
                    } else {
                        $("#radioDaili1").removeAttr("checked");
                        $("#radioDaili2").attr("checked", "checked");
                        form.render();
                    }

                    if (res.object.agentScope == 0) {
                        $("#agentNational1").attr("checked", "checked");
                        $("#agentNational2").removeAttr("checked");
                        form.render();
                    } else {
                        $("#agentNational1").removeAttr("checked");
                        $("#agentNational2").attr("checked", "checked");
                        form.render();
                    }


                }
            });
        });
        $.ajax({
            type: "GET",
            url: '/agentEntity/findAgent',
            dataType:"json",
            contentType: "application/json;charset=UTF-8",
            success: function(res){
                var html2 = '<option value="">'+res.object.companyName+'</option>';
                if(res.success){
                    $("#agentIdAgentId").html(html2);
                    form.render('select');
                }
            }
        });

        function dateFormat(date) {
            var dateee = new Date(date).toJSON();
            console.log("日期格式", dateee);
            return new Date(+new Date(dateee) + 8 * 3600 * 1000)
                .toISOString()
                .replace(/T/g, " ")
                .replace(/\.[\d]{3}Z/, "");
        }
    });

</script>
<!--获取表单信息，提交表单-->
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(agent-form)', function (data) {
            layer.msg(JSON.stringify(data.field));
            var dateBegin = data.field.agentCreateTime;
            var dateEnd = data.field.agentEndTime;
            dateBegin = dateBegin.substring(0, 19);
            dateBegin = dateBegin.replace(/-/g, '-');
            dateBegin = dateBegin.substring(0, 19);
            dateEnd = dateEnd.replace(/-/g, '-');
            var timestamp1 = new Date(dateBegin).getTime();
            var timestamp2 = new Date(dateEnd).getTime();
            var AgentEntity = {
                "id": data.field.agentUuid,
                //"agentNumber": data.field.agentNumber,
                "companyName": data.field.agentCompanyName,
                "username": data.field.agentUsername,
                "password": data.field.agentPassword,
                "name": data.field.agentName,
                "card": data.field.agentCard,
                "phone": data.field.agentPhone,
                //"agentIt":data.field.agentIt,
                "branch": data.field.agentBranch,
                "bankCardName": data.field.agentBankCardName,
                "bankCardNumber": data.field.agentBankCard,
                "email": data.field.agentEmail,
                //"agentAgent":data.field.agentAgent,
                //"agentNational":data.field.agentNational,
                "remark": data.field.agentNote,
                "agentIdAgentId":data.field.agentIdAgentId,
                "overdueTime": timestamp2,
                "createTime": timestamp1,
                "status": data.field.agentState,
                "agentScope": data.field.agentNational,
                "agentType": data.field.agentAgent,
            }
            console.log("值data", data);
            $.ajax({
                type: "POST",
                url: "/agentEntity/update/" + data.field.agentUuid,
                contentType: "application/json;charset=UTF-8",
                data: JSON.stringify(AgentEntity),
                async: true,
                success: function (res) {
                    console.log("res", res);
                    if (res.success) {
                        $(document).ready(function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            console.log("index值", index)
                            close();
                        });
                        //layer.msg(data.message);
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
            return false;
        });
    });
</script>
<!--关闭弹层-->
<script>
    function close() {
        console.log("关闭方法执行");
        layui.use('layer', function () {
            var $ = layui.$,
                layer = layui.layer,
                index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            var active = {
                close: function () {
                    var id = '#LAY_layer_iframe_demo',
                        mark = $('#LAY_mark');
                    parent.layer.msg('修改成功');
                    parent.layer.tips('Look here', id, {
                        time: 5000
                    });
                    window.parent.location.reload();
                    parent.layer.close(index);
                }
            }
            $('.layui-btn-container .layui-btn').on('click', function () {
                var othis = $(this),
                    type = othis.data('type');
                active[type] && active[type].call(this);
            });
        });
    }
</script>

</html>